package com.ruoyi.web.controller.decision;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.decision.domain.TaskStrategyModel;
import com.ruoyi.decision.service.ITaskStrategyModelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 决策方案与优化策略与优化模型中间Controller
 * 
 * @author zbw
 * @date 2022-08-24
 */
@RestController
@RequestMapping("/decision/taskstrategymodel")
public class TaskStrategyModelController extends BaseController
{
    @Autowired
    private ITaskStrategyModelService taskStrategyModelService;

    /**
     * 查询决策方案与优化策略与优化模型中间列表
     */
    @PreAuthorize("@ss.hasPermi('decision:taskstrategymodel:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskStrategyModel taskStrategyModel)
    {
        startPage();
        List<TaskStrategyModel> list = taskStrategyModelService.selectTaskStrategyModelList(taskStrategyModel);
        return getDataTable(list);
    }

    /**
     * 导出决策方案与优化策略与优化模型中间列表
     */
    @PreAuthorize("@ss.hasPermi('decision:taskstrategymodel:export')")
    @Log(title = "决策方案与优化策略与优化模型中间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskStrategyModel taskStrategyModel)
    {
        List<TaskStrategyModel> list = taskStrategyModelService.selectTaskStrategyModelList(taskStrategyModel);
        ExcelUtil<TaskStrategyModel> util = new ExcelUtil<TaskStrategyModel>(TaskStrategyModel.class);
        util.exportExcel(response, list, "决策方案与优化策略与优化模型中间数据");
    }

    /**
     * 获取决策方案与优化策略与优化模型中间详细信息
     */
    @PreAuthorize("@ss.hasPermi('decision:taskstrategymodel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(taskStrategyModelService.selectTaskStrategyModelById(id));
    }

    /**
     * 新增决策方案与优化策略与优化模型中间
     */
    @PreAuthorize("@ss.hasPermi('decision:taskstrategymodel:add')")
    @Log(title = "决策方案与优化策略与优化模型中间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskStrategyModel taskStrategyModel)
    {
        TaskStrategyModel taskId = new TaskStrategyModel();
        taskId.setTaskId(taskStrategyModel.getTaskId());
        List<TaskStrategyModel> taskList = taskStrategyModelService.selectTaskStrategyModelList(taskId);
        for (TaskStrategyModel configure : taskList) {
            if (configure.getStrategyId().equals(taskStrategyModel.getStrategyId())){
                if (configure.getModelId().equals(taskStrategyModel.getModelId())){
                    taskStrategyModel.setId(configure.getId());
                    return toAjax(taskStrategyModelService.updateTaskStrategyModel(taskStrategyModel));
                }
            }
        }
        return toAjax(taskStrategyModelService.insertTaskStrategyModel(taskStrategyModel));
    }

    /**
     * 修改决策方案与优化策略与优化模型中间
     */
    @PreAuthorize("@ss.hasPermi('decision:taskstrategymodel:edit')")
    @Log(title = "决策方案与优化策略与优化模型中间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskStrategyModel taskStrategyModel)
    {
        return toAjax(taskStrategyModelService.updateTaskStrategyModel(taskStrategyModel));
    }

    /**
     * 删除决策方案与优化策略与优化模型中间
     */
    @PreAuthorize("@ss.hasPermi('decision:taskstrategymodel:remove')")
    @Log(title = "决策方案与优化策略与优化模型中间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(taskStrategyModelService.deleteTaskStrategyModelByIds(ids));
    }
}
